//
//  CalendarHomeViewController.m
//  Calendar
//
//  Created by 张凡 on 14-6-23.
//  Copyright (c) 2014年 张凡. All rights reserved.
//

// 版权属于原作者
// http://code4app.com (cn) http://code4app.net (en)
// 发布代码于最专业的源码分享网站: Code4App.com

#import "CalendarHomeViewController.h"
#import "Color.h"

@interface CalendarHomeViewController (){    
    int daynumber;//天数
    int optiondaynumber;//选择日期数量
//    NSMutableArray *optiondayarray;//存放选择好的日期对象数组
}
//酒店日历
@property (nonatomic, strong)NSMutableArray * dataArray;
@property (nonatomic, strong)UIView * mainView;
@end

@implementation CalendarHomeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad{
    [super viewDidLoad];
    //回退键
    UIButton * backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30/WIDTH_6_SCALE, 30/WIDTH_6_SCALE)];
    [backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    //确定键
    UIButton * sureBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50/WIDTH_6_SCALE, 30/WIDTH_6_SCALE)];
    [sureBtn addTarget:self action:@selector(sureBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [sureBtn setTitle:@"确定" forState:UIControlStateNormal];
    [sureBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    sureBtn.titleLabel.font = DEF_FontSize_14;
    UIBarButtonItem * rightItem = [[UIBarButtonItem alloc] initWithCustomView:sureBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.cleanArray();
}
#pragma mark - 设置方法
//飞机初始化方法
- (void)setAirPlaneToDay:(int)day ToDateforString:(NSString *)todate{
    daynumber = day;
    optiondaynumber = 1;//选择一个后返回数据对象
    super.calendarMonth = [self getMonthArrayOfDayNumber:daynumber ToDateforString:todate];
    [super.collectionView reloadData];//刷新
}

//酒店初始化方法
- (void)setHotelToDay:(int)day ToDateforString:(NSString *)todate{
    daynumber = day;
    optiondaynumber = 2;//选择两个后返回数据对象
    super.calendarMonth = [self getMonthArrayOfDayNumber:daynumber ToDateforString:todate];
    [super.collectionView reloadData];//刷新
}
//火车初始化方法
- (void)setTrainToDay:(int)day ToDateforString:(NSString *)todate{
    daynumber = day;
    optiondaynumber = 1;//选择一个后返回数据对象
    super.calendarMonth = [self getMonthArrayOfDayNumber:daynumber ToDateforString:todate];
    [super.collectionView reloadData];//刷新
}
#pragma mark - 逻辑代码初始化
//获取时间段内的天数数组
- (NSMutableArray *)getMonthArrayOfDayNumber:(int)day ToDateforString:(NSString *)todate{
    NSDate *date = [NSDate date];
    NSDate *selectdate  = [NSDate date];
    if (todate) {
        selectdate = [selectdate dateFromString:todate];
    }
    super.Logic = [[CalendarLogic alloc]init];
    return [super.Logic reloadCalendarView:date selectDate:selectdate  needDays:day];
}
#pragma mark - 设置标题
- (void)setCalendartitle:(NSString *)calendartitle{
    [self.navigationItem setTitle:calendartitle];
}
- (void)backBtnClick{
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
- (void)sureBtnClick{
    if (self.getSpecificDate) {
        [self.navigationController dismissViewControllerAnimated:YES completion:nil];
        self.getSpecificDate();
    }
}
@end
